#ifndef K_ACCEPTOR_ACTION_H
#define K_ACCEPTOR_ACTION_H
#pragma once

#include "KSocketAction.h"

class KAcceptorAction : public KSocketAction {
public:
    explicit KAcceptorAction(LONG max = -1, LONG extra = 0);
public:
    LONG clients() const                { return m_clients; }
    LONG extraAccepts() const           { return m_extra; }
    LONG maxClients() const             { return m_max; }
    void setMaxClients(LONG max = -1)   { m_max = max; }
    LONG totalClients() const           { return m_total; }
protected:
    void decreaseClients();
protected:
    virtual void onClientsChanged(LONG current) {}
    virtual void onFault(KDef::SockError type, DWORD error, LONG extra);
    virtual bool onNewClient(KSocket *client) = 0;
private:
    void onAccepted(KSocket *client);
    void onFatalError(KDef::SockError type, DWORD error);
private:
    volatile LONG m_clients, m_extra, m_total;
    LONG m_max;
};

#endif // K_ACCEPTOR_ACTION_H